package org.cnc.explain.lifecycle.beaninstance_6;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;

/**
 * <p>
 * #TODO: desc
 * </p>
 *
 * @author zhiyong.tan
 * @since 2022-08-28
 */
public class MyAfterInstantiationAwareBeanPostProcessor implements InstantiationAwareBeanPostProcessor {

	@Override
	public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
		if("beanInstanceBean".equals(beanName)){
			System.out.println("Bean实例化后置拦截:" + beanName);
			BeanInstanceBean ob = (BeanInstanceBean) bean;
			ob.setBeanInstanceConstructInjectBean(
					new BeanInstanceConstructInjectBean("changed by postProcessAfterInstantiation")
			);
		}
		return InstantiationAwareBeanPostProcessor.super.postProcessAfterInstantiation(bean, beanName);
	}
//	@Override
//	public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
//		if("beanInstanceBean".equals(beanName)){
//			return false;
//		}
//		return InstantiationAwareBeanPostProcessor.super.postProcessAfterInstantiation(bean, beanName);
//	}
}
